

#import "FAMAgeViewController.h"
#import <Foundation/Foundation.h>
@interface FAMAgeViewController ()
@property (weak, nonatomic) IBOutlet UIView *FAMPageBackView;
@property (weak, nonatomic) IBOutlet UIDatePicker *FAMDatePicker;
@property (nonatomic, assign)NSInteger FAMNowTime;
@end

@implementation FAMAgeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    [self FAM_showUi];
}

- (void)FAM_showUi{
    self.FAMPageBackView.layer.shadowColor = kCustom0xColor(0x000000, 1.0).CGColor;
    self.FAMPageBackView.layer.shadowOpacity = 0.15;
    self.FAMPageBackView.layer.shadowRadius = 1.5;
    self.FAMPageBackView.layer.shadowOffset = CGSizeMake(2, 2);
    self.FAMDatePicker.datePickerMode = UIDatePickerModeDate;
    self.FAMDatePicker.maximumDate = [NSDate new];
    self.FAMNowTime = ([FAMTool FAM_getNowTimeTimestamp]).integerValue;
    NSDate *today = [NSDate date];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:today];
    [components setYear:[components year] - 20];
    NSDate *twentyYearsAgoToday = [calendar dateFromComponents:components];
    [self.FAMDatePicker setDate:twentyYearsAgoToday];
    [self.FAMFoodmateUserdataDictionary setValue:@"20" forKey:@"age"];
    
}
- (IBAction)FAM_backButtonClick:(UIButton *)sender {
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)FAM_nextButtonClick:(UIButton *)sender {
    FAMHeightViewController *vc = [FAMHeightViewController new];
    vc.FAMFoodmateUserdataDictionary = self.FAMFoodmateUserdataDictionary;
    [self.navigationController pushViewController:vc animated:YES];
}
- (IBAction)FAM_pickerValueChangedClick:(UIDatePicker *)sender {
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    dateFormatter.dateStyle = NSDateFormatterMediumStyle;
    dateFormatter.timeStyle = NSDateFormatterShortStyle;
    dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    dateFormatter.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"Asia/Beijing"];
    NSString *dateString = [dateFormatter stringFromDate:sender.date];
    NSDate *tempDate = [dateFormatter dateFromString:dateString];
    NSInteger choseTime = [tempDate timeIntervalSince1970] * 1000;
    NSInteger age = (self.FAMNowTime - choseTime)/1000/3600/24/365;
    self.FAMFoodmateUserdataDictionary[@"age"] = [NSString stringWithFormat:@"%ld",age];
}


@end
